# -*- coding: utf-8 -*-
# tasks_02.py
from flask import Flask
from celery import Celery


def make_celery(app):
    celery=Celery(__name__,broker='redis://10.10.100.21:6379/2')
    return celery

app = Flask(__name__)
app.config.update(
    CELERY_BROKER_URL='redis://10.10.100.21:6379/2',
    CELERY_RESULT_URL='redis://10.10.100.21:6379/2',
    CELERY_TASK_SERIALIZER='json',
    CELERY_RESULT_SERIALIZER='json'
)

celery = make_celery(app)
celery.conf.update(app.config)

@celery.task(name='sendmail')
def sendmail(mail):
    print('sending mail to %s...' % mail['to'])
    #time.sleep(2.0)
    print('mail sent.')
    return mail['to']


if __name__=="__main__":
    #Worker
    #task='celery -A tasks_2.celery  worker -c 3 --loglevel=info'
    #os.system(task)
    #sendmail.delay(dict(to='jk409o@qq.com'))
    for i in range(1,10):
        ret=sendmail.delay({'to':i})
        print ret,'----->',i